import axios  from "axios";
import base from './base';


const api = {
    // 注册
    register(params){
        return axios.post(base.baseUrl + base.register,params)
    },
    // 登录
    loginUser(params){
        return axios.post(base.baseUrl + base.loginUser,params)
    },
    loginAdmin(params){
        return axios.post(base.baseUrl + base.loginAdmin,params)
    },
    menu(params){
        return axios.get(base.baseUrl + base.menu +'?type='+params)
    },
    getUserList(){
        return axios.get(base.baseUrl + base.getUserList)
    },
    getUserInfo(params){
        return axios.get(base.baseUrl + base.getUserInfo + params)
    },
    searchUser(params){
        return axios.get(base.baseUrl + base.searchUser+'?query='+params);
    },
    removeUser(params){
        return axios.delete(base.baseUrl + base.removeUser+'?query='+params);
    },
    addUser(params){
        return axios.post(base.baseUrl + base.addUser,params);
    },
    editUser(params){
        return axios.put(base.baseUrl + base.editUser,params);
    },
    editPassword(pload){
        return axios.put(base.baseUrl + base.editPassword,pload);
    },
    // 首页部分
    getTotalNum(params){
        return axios.get(base.baseUrl + base.getTotalNum+'?type='+params);
    },
    // 球馆部分
    getStadiumList(query){
        if(query.pageSize && query.currentPage){
        return axios.get(base.baseUrl + base.getStadiumList+`?currentPage=${query.currentPage}&pageSize=${query.pageSize}`);
        }
        return axios.get(base.baseUrl + base.getStadiumList);
    },
    getStadiumListById(sid){
        if(sid){
        return axios.get(base.baseUrl + base.getStadiumListById+`?sid=${sid}`);
        }
        return axios.get(base.baseUrl + base.getStadiumListById);
    },
    addStadium(pload){
        return axios.post(base.baseUrl + base.addStadium,pload);
    },
    editStadium(pload){
        return  axios.put(base.baseUrl + base.editStadium,pload);
    },
    removeStadium(query){
        return axios.delete(base.baseUrl + base.removeStadium+'?query='+query);
    },
    searchStadium(pload){
        if(pload.pagination.pageSize && pload.pagination.currentPage)
         return axios.get(base.baseUrl + base.searchStadium+'?query='+pload.query+'&currentPage='+pload.pagination.currentPage+'&pageSize='+pload.pagination.pageSize);
        return  axios.get(base.baseUrl + base.searchStadium+'?query='+pload.query);
    },
    // 场地部分
    getCourtList(sid){
        return axios.get(base.baseUrl + base.getCourtList+'?sid='+sid);
    },
    addCourt(pload){
        return axios.post(base.baseUrl + base.addCourt,pload);
    },
    editCourt(pload){
        return axios.put(base.baseUrl + base.editCourt,pload);
    },
    removeCourt(cid){
        return axios.delete(base.baseUrl + base.removeCourt+'?cid='+cid);
    },
    // 订单部分
    getOrderList(){
        return axios.get(base.baseUrl + base.getOrderList);
    },
    // 获取订单信息(分页)
    getOrderListByPage(query){
        if(query.pageSize && query.currentPage){
            if(query.uid)
             return axios.get(base.baseUrl + base.getOrderListByPage+`?currentPage=${query.currentPage}&pageSize=${query.pageSize}&uid=${query.uid}`);
            return axios.get(base.baseUrl + base.getOrderListByPage+`?currentPage=${query.currentPage}&pageSize=${query.pageSize}`);
            }
            if(query.uid)  return axios.get(base.baseUrl + base.getOrderListByPage+`?uid=${query.uid}`);
            return axios.get(base.baseUrl + base.getOrderListByPage);
    },
    addOrderList(pload){
        return axios.post(base.baseUrl + base.addOrderList,pload);
    },
    removeOrderList(oid){
        return axios.delete(base.baseUrl + base.removeOrderList+'?oid='+oid);
    },
    searchOrderList(pload){
       if(pload.pagination.pageSize && pload.pagination.currentPage)
         return axios.get(base.baseUrl + base.searchOrderList+'?query='+pload.query+'&currentPage='+pload.pagination.currentPage+'&pageSize='+pload.pagination.pageSize);
       return  axios.get(base.baseUrl + base.searchOrderList+'?query='+pload.query);
    },
    editOrderState(pload){
        return axios.put(base.baseUrl + base.editOrderState,pload);
    },
    // 评论部分
    getCommentList(){
        return axios.get(base.baseUrl + base.getCommentList);
    },
    // 分页获取评论信息
    getCommentListByPage(query){
        if(query.pageSize && query.currentPage){
        return axios.get(base.baseUrl + base.getCommentListByPage+`?currentPage=${query.currentPage}&pageSize=${query.pageSize}`);
        }
        return axios.get(base.baseUrl + base.getCommentListByPage);
    },
    removeCommentList(comId){
        return axios.delete(base.baseUrl + base.removeCommentList+'?comId='+comId);
    },
    searchCommentList(pload){
        if(pload.pagination.pageSize && pload.pagination.currentPage)
         return axios.get(base.baseUrl + base.searchCommentList+'?query='+pload.query+'&currentPage='+pload.pagination.currentPage+'&pageSize='+pload.pagination.pageSize);
        return  axios.get(base.baseUrl + base.searchCommentList+'?query='+pload.query);
    },
    addCommentList(pload){
        return axios.post(base.baseUrl + base.addCommentList,pload);
    },
    // 公告部分
    getNoticeList(){
        return axios.get(base.baseUrl + base.getNoticeList);
    },
    addNoticeList(pload){
        return axios.post(base.baseUrl + base.addNoticeList,pload);
    },
    removeNoticeList(nId){
        return axios.delete(base.baseUrl + base.removeNoticeList+'?nId='+nId);
    },
    editNoticeList(pload){
        return axios.put(base.baseUrl + base.editNoticeList,pload);
    }
}   

export default api;